#include "Blur.h"

namespace Utilities {
	unsigned int Blur::DepthGaussianBlur(unsigned int textureID,unsigned int framebuffer,Shader* shader,float width,float height,unsigned int screenVAO)
	{
		glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
		glDepthMask(GL_TRUE);
		glEnable(GL_DEPTH_TEST);
		glClear(GL_DEPTH_BUFFER_BIT);

		
		shader->use();
		shader->setInt("image", 0);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, textureID);

		for (unsigned int index = 0; index < 5; ++index) {
			// horizontal blur.
			shader->setInt("horizontal", 1);
			glBindVertexArray(screenVAO);
			glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
			// copy to target texture.
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);

			// vertical blur.
			shader->setInt("horizontal", 0);
			glBindVertexArray(screenVAO);
			glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

			// copy to target texture.
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
		}

		

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		return textureID;
	}
}